package com.ideabove.heart;

import java.util.Timer;

import com.ideabove.heart.manager.AppManager;
import com.ideabove.heart.manager.MoeManager;
import com.ideabove.heart.manager.ScheduleManager;
import com.ideabove.heart.manager.SoundManager;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ImageView;
import android.app.Activity;
import android.content.Intent;

public class FailActivity extends MyActivity {
	Activity mActivity;
	int mcount = 0;
	Timer mTimer;
	SoundManager soundMgr;
	int SOUND_IDX = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fail_call);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 
				| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD 
				| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON 
				| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); 

		mActivity = this;
		AppManager.pause(FailActivity.this);

		// 효과음
		soundMgr = new SoundManager(this);
		soundMgr.addSound(SOUND_IDX, R.raw.button_press);
		
		// 전화하기
		ImageView fail_call_again = (ImageView)findViewById(R.id.fail_call_again);
		fail_call_again.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				soundMgr.playSound(SOUND_IDX);
				
				// fail cnt 를 다시  0으로 세팅한다.
				ScheduleManager scheMgr = new ScheduleManager(FailActivity.this);
				scheMgr.initFailCnt();
				
				// 전화를 못받은 모에화면을 띠워준다...
				MoeManager.setWhatWillIdo(MoeManager.DO_FAIL_CALL); // 메인에서 모에를 호출함.
				Intent intent = new Intent(FailActivity.this, SendingActivity.class);
				startActivity(intent);
				finish();
				
				AppManager.start();
			}
		});
		
		// 전화무시
		ImageView fail_call_ignore = (ImageView)findViewById(R.id.fail_call_ignore);
		fail_call_ignore.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				soundMgr.playSound(SOUND_IDX);
				
				// fail cnt 를 다시  0으로 세팅한다.
				ScheduleManager scheMgr = new ScheduleManager(FailActivity.this);
				scheMgr.initFailCnt();
				
				Intent intent = new Intent(FailActivity.this, IntroActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
				finish();
				
				AppManager.start();
			}
		});
	
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onStart();
		AppManager.pause(FailActivity.this);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		AppManager.pause(FailActivity.this);
	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		finish();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		if(soundMgr != null){
			soundMgr.clear();
		}
		super.onDestroy();
	}

}
